const app = getApp()

Component({
  properties: {
   
  },
  data: {
    isOpen: false,
    isLong: false,

    lang: app.globalData.language
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached: function () { 
      let model = app.globalData.model;
      this.setData({
        isLong: model,
        lang: app.globalData.language
      })
    },
    moved: function () { },
    detached: function () { },
  },
  methods: {
    closeMenuTap: function (e) {
      this.setData({
        isOpen: false
      })
    },
    openMenuTap: function (e) {
      this.setData({
        isOpen: true
      })
    },
    menuLanguageTap: function(e) {
      let language = app.globalData.language
      if (language == 'cn'){
        language = 'en'
      }else{
        language = 'cn'
      }
      this.setData({
        isOpen: false,
        lang: language
      })
      // 修改app.js
      app.globalData.language = language
      // 传值到父级
      let detail = {lang: language};
      this.triggerEvent('myevent', detail);
      // 切换底部tabbar中英文
      if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
          lang: language
        })
      }
    }
  }
});
